package apiday08.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ReflectDemo2 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("apiday08.homework.Person");
        Constructor c = cls.getConstructor(String.class);
        Object obj = c.newInstance("王二");
        System.out.println(cls.getSimpleName()+":"+obj);

        Constructor c1 = cls.getConstructor(String.class,int.class);
        Object obj1 = c1.newInstance("企鹅",20);
        System.out.println(cls.getSimpleName()+":"+obj1);

        Method method = cls.getMethod("playGame");
        method.invoke(obj);

        Method method1 = cls.getMethod("say", String.class);
        method1.invoke(obj,"评论");

        Method method2 = cls.getMethod("say", String.class, int.class);
        method2.invoke(obj,"目前",5);

    }
}
